maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=virtctl
pkgver=1.3.1
pkgrel=0
pkgdesc="CLI client for KubeVirt - the Kubernetes Virtualization API"
url="https://kubevirt.io/"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/kubevirt/kubevirt/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/kubevirt-$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local _goldflags="
	-X kubevirt.io/client-go/version.gitVersion=v$pkgver
	-X kubevirt.io/client-go/version.gitCommit=AlpineLinux
	-X kubevirt.io/client-go/version.gitTreeState=clean
	-X kubevirt.io/client-go/version.buildDate=$(date -u "+%Y-%m-%dT%H:%M:%SZ" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	"
	go build -v -ldflags "$_goldflags" ./cmd/virtctl/virtctl.go

	for shell in bash fish zsh; do
		./$pkgname completion $shell > $pkgname.$shell
	done
}

check() {
	# Only run unittest for virtctl
	go test -ldflags "-X kubevirt.io/client-go/version.gitVersion=v$pkgver" ./pkg/virtctl/...
}

package() {
	install -Dm755 $pkgname -t "$pkgdir"/usr/bin/

	install -Dm644 $pkgname.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -Dm644 $pkgname.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
d34f35713f73ea5bf02e3421bf0fae8ce5c66c5123da5018179baf9f1e72cacea409326cf797fd66da28fdb336d40dc254bdf94cb57de3c0c5f280d085ecd584  virtctl-1.3.1.tar.gz
"
